package com.wlyuan.open.infrastructure.converter;

import com.wlyuan.core.domain.MappingIds;
import com.wlyuan.core.marker.MappingValue;
import com.wlyuan.open.dao.entity.SourceDataDO;
import com.wlyuan.open.dao.entity.SourceRelationDO;
import com.wlyuan.open.domain.client.utils.MappingOpenClient;
import com.wlyuan.open.domain.source.SourceData;
import com.wlyuan.open.domain.source.SourceRelation;
import com.wlyuan.open.domain.source.utils.MappingSource;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

/**
 * @author yuanzheng
 */
public class SourceConverter {
    @Mapper(uses = {
            MappingIds.class,
            MappingValue.class,
            MappingSource.class,
            MappingOpenClient.class
    })
    public interface Converter {
        SourceData convertData(SourceDataDO source);

        @InheritInverseConfiguration
        SourceDataDO convertData(SourceData source);

        SourceRelationDO convertRelation(SourceRelation source);

        @InheritInverseConfiguration
        SourceRelation convertRelation(SourceRelationDO source);
    }

    private static final Converter CONVERTER = Mappers.getMapper(Converter.class);

    public static SourceDataDO convertRaw(SourceData source) {
        return CONVERTER.convertData(source);
    }

    public static SourceData convertRaw(SourceDataDO source) {
        return CONVERTER.convertData(source);
    }

    public static SourceRelation convertRelation(SourceRelationDO source) {
        return CONVERTER.convertRelation(source);
    }

    public static SourceRelationDO convertRelation(SourceRelation source) {
        return CONVERTER.convertRelation(source);
    }
}
